package top.api.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResUlt;
import top.api.domain.dto.*;
import top.api.service.ClassService;
import top.api.service.CourseService;

import java.util.List;

@RestController
@RequestMapping("/course")
@RequiredArgsConstructor
@Api(tags = "课程管理")
public class CourseController {
    private final CourseService baseService;

    @GetMapping
    @SaCheckRole("admin")
    @ApiOperation("分页查询")
    public ResUlt<?> pageList(@Validated PageDto pageDto, Integer id,String coursename){
        return baseService.pageList(pageDto,id,coursename);
    }

    @GetMapping("/{id}")
    @SaCheckRole("admin")
    @ApiOperation("查询课程详情")
    public ResUlt<?> getCourseInfo(@PathVariable Integer id){
        return baseService.getCourseInfo(id);
    }

    @PostMapping
    @SaCheckRole("admin")
    @ApiOperation("添加课程")
    public ResUlt<?> addCourse(@RequestBody @Validated CourseAddDto courseAddDto){
        return baseService.addCourse(courseAddDto);
    }

    @PutMapping
    @SaCheckRole("admin")
    @ApiOperation("修改课程")
    public ResUlt<?> editCourse(@RequestBody @Validated CourseEditDto courseEditDto){
        return baseService.editCourse(courseEditDto);
    }

    @DeleteMapping("/{ids}")
    @SaCheckRole("admin")
    @ApiOperation("删除课程")
    public ResUlt<?> delCourse(@PathVariable List<Integer> ids){
        return baseService.delCourse(ids);
    }
}
